<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>XMLHttpRequest function demo</title>
  <script>
    window.onload = () => {
      let obtn = document.getElementById('btn')
      obtn.addEventListener('click', () => {
        let xhr = new XMLHttpRequest()

        xhr.open('GET', 'data/1.txt', true)

        xhr.send()

        xhr.onreadystatechange = () => {
          if (xhr.readyState === 4) {
            if (xhr.stauts >= 200 && xhr.status > 300 || xhr.status === 304) {
              console.log('success', xhr.responseText)
            } else {
              console.log('failed')
            }
          }
        }
      }, false)
    }
  </script>
</head>
<body>
  <input type="button" value="按钮" id="btn" />
</body>
</html>